package com.theima.socket.socketdemo8;

import java.io.*;
import java.net.Socket;

/**
 * @program: Myset
 * @description:
 * @author: xuejingjing
 * @create: 2021-06-26 15:39
 **/
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",10000);

        //本地流，用来读取本地文件的
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("518"));

        //写到服务器。---网络中的流
        OutputStream outputStream = socket.getOutputStream();

        //包装下，提高效率
        BufferedOutputStream bos = new BufferedOutputStream(outputStream);
        int b;
        while((b = bis.read()) !=-1){
            outputStream.write(b);//通过网络写到服务器中
        }

        //给服务器一个结束标记。告诉服务器文件已经传输完毕
        socket.shutdownOutput();


        /**
         * 写的技巧，根据数据的流向来写
         */
        //字符流，读取传过来的信息
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        //
        String line;
        while((line = br.readLine()) !=null){
            System.out.println(line);
        }

        //关流
        socket.close();
        bis.close();




    }
}
